//
//  YJHomeHeaderView.m
//  YJB
//
//  Created by YJB on 16/9/3.
//  Copyright © 2016年 YJB. All rights reserved.
//

#import "YJHomeHeaderView.h"
#import "YJVerticalButton.h"
#import "Masonry.h"

@implementation YJHomeHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = WHITECOLOR;
        NSMutableArray *buttons = [NSMutableArray array];
        NSArray *titles = @[@"土豪",@"理财",@"购物",@"智能",@"更多"];
        NSArray *images =  @[@"local-tyrants--_icon",@"financial--_icon",@"mall-_icon",@"smart--_icon",@"more-and-more--_icon"];
        for (int i = 0; i < titles.count; i ++)
        {
            YJVerticalButton *button = [[YJVerticalButton alloc]init];
            button.tag = i + 10;
            [button setTitle:titles[i] forState:UIControlStateNormal];
            [button setTitleColor:kUIColorFromRGB(0x333333)  forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:16.0f];
            [button setImage:Image(images[i]) forState:UIControlStateNormal];
            [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:button];
            [buttons addObject:button];
        }
        [buttons mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:5 * GRIDW leadSpacing:14 tailSpacing:14];
        [buttons mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@0);
            make.height.mas_equalTo(self.mas_height);
        }];
    }
    return self;
}

- (void)buttonClick:(YJVerticalButton *)button
{
    YJHomeHeaderViewButtonType type = 0;
    switch (button.tag) {
        case 10:
            type = YJHomeHeaderViewButtonTypeRichMan;
            break;
        case 11:
            type = YJHomeHeaderViewButtonTypeMoneyManage;
            break;
        case 12:
            type = YJHomeHeaderViewButtonTypeStore;
            break;
        case 13:
            type = YJHomeHeaderViewButtonTypeIntelligent;
            break;
        case 14:
            type = YJHomeHeaderViewButtonTypeMore;
            break;
    }
    if (self.buttonClickBlock)
        self.buttonClickBlock(type);
}

@end
